<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="activityList">
      <el-table-column label="名称" align="center" prop="name"/>
      <el-table-column label="创建时间" align="center" prop="creatTime" width="180"/>
      <el-table-column label="有效时间" align="center" prop="startTime" width="180">
        <template scope="scope">
          <span>{{scope.row.startTime }}至{{scope.row.endTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="参与活动人数" align="center" prop="status">
        <template scope="scope">
          <span>{{scope.row.count}}人
              <el-button
                v-if="scope.row.count>0"
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleopen(scope.row)"
                v-hasPermi="['bigbag:activity:edit']"
              >查看
          </el-button>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template scope="scope">
          <span>{{scope.row.status==0?"正常":"过期"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bigbag:activity:edit']"
          >查看明细
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--查看活动人数详细-->
    <el-dialog title="查看活动人数" :visible.sync="open" width="900px" append-to-body>
      <el-table :data="userForm">
        <el-table-column label="姓名" align="center" prop="nickName"/>
        <el-table-column label="手机号" align="center" prop="phonenumber" width="180"/>
        <el-table-column label="剩余抽奖次数" align="center" prop="surplus" width="180"/>
        <el-table-column label="剩余抽奖次数" align="center" prop="surplus" width="180"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleopenDetail(scope.row)"
            >查看明细
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--查看中奖明细-->
    <el-dialog title="查看中奖明细" :visible.sync="openDetail" width="900px" append-to-body>
      <el-table :data="detailForm">
        <el-table-column label="任务" align="center">
          <template>
            <span>抽奖</span>
          </template>
        </el-table-column>
        <el-table-column label="时间" align="center" prop="lotteryTime" width="180"/>
        <el-table-column label="奖励" align="center" prop="name" width="180"/>
        <el-table-column label="领取方式" align="center" prop="mode" width="180">
          <template scope="scope">
            {{scope.row.mode==1?"现金":scope.row.mod==2?"支付宝":"现场领取"}}
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDetail">取 消</el-button>
      </div>
    </el-dialog>
  </div>


</template>

<script>
  import {listActivity, listUser, listPrize} from "@/api/bigbag/statistics";

  export default {
    name: "Activity",
    dicts: ['market_rule'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 营销活动表格数据
        activityList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openDetail: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {},
        detailForm: [],
        // 表单校验
        rules: {},
        //用户人数详细
        userForm: [],
        //活动Id
        activityId: null,
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询营销活动列表 */
      getList() {
        this.loading = true;
        listActivity(this.queryParams).then(response => {
          this.activityList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
      },
      cancelDetail() {
        this.openDetail = false;
        this.open = true;
      },
      handleopen(row) {
        this.activityId = row.id;
        listUser(row.id).then(res => {
          this.userForm = res.data;
          this.open = true;
        })
      },
      //查看中奖明细
      handleopenDetail(row) {
        listPrize(row.userId, this.activityId).then(res => {
          this.detailForm = res.data;
          this.open = false;
          this.openDetail = true;
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
